package com.ruoyi.web.controller.part;

import java.util.List;

import com.ruoyi.system.domain.PartLot;
import com.ruoyi.system.service.IPartLotService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PartPost;
import com.ruoyi.system.service.IPartPostService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * partpostController
 *
 * @author ruoyi
 * @date 2023-12-06
 */
@Controller
@RequestMapping("/part/post")
public class PartPostController extends BaseController {
    private String prefix = "part/post";

    @Autowired
    private IPartPostService partPostService;

    @Autowired
    private IPartLotService partLotService;

    @RequiresPermissions("system:post:view")
    @GetMapping()
    public String post() {
        return prefix + "/post";
    }

    /**
     * 查询partpost列表
     */
    @RequiresPermissions("system:post:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PartPost partPost) {
        startPage();
        List<PartPost> list = partPostService.selectPartPostList(partPost);
        return getDataTable(list);
    }

    /**
     * 导出partpost列表
     */
    @RequiresPermissions("system:post:export")
    @Log(title = "partpost", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PartPost partPost) {
        List<PartPost> list = partPostService.selectPartPostList(partPost);
        ExcelUtil<PartPost> util = new ExcelUtil<PartPost>(PartPost.class);
        return util.exportExcel(list, "partpost数据");
    }

    /**
     * 新增partpost
     */
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        //因为进入到该页面的时候需要显示车停场的信息----下拉框
        List<PartLot> partLots = partLotService.selectPartLotList(null);
        mmap.put("partLots", partLots);
        return prefix + "/add";
    }

    /**
     * 新增保存partpost
     */
    @RequiresPermissions("system:post:add")
    @Log(title = "partpost", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PartPost partPost) {
        return toAjax(partPostService.insertPartPost(partPost));
    }

    /**
     * 修改partpost
     */
    @RequiresPermissions("system:post:edit")
    @GetMapping("/edit/{partPostId}")
    public String edit(@PathVariable("partPostId") Long partPostId, ModelMap mmap) {
        PartPost partPost = partPostService.selectPartPostByPartPostId(partPostId);
        mmap.put("partPost", partPost);
        //因为进入到修改页面的时候需要显示停车场的信息----下拉框
        List<PartLot> partLots = partLotService.selectPartLotList(null);
        mmap.put("partLots", partLots);
        return prefix + "/edit";
    }

    /**
     * 修改保存partpost
     */
    @RequiresPermissions("system:post:edit")
    @Log(title = "partpost", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PartPost partPost) {
        return toAjax(partPostService.updatePartPost(partPost));
    }

    /**
     * 删除partpost
     */
    @RequiresPermissions("system:post:remove")
    @Log(title = "partpost", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(partPostService.deletePartPostByPartPostIds(ids));
    }
}
